package com.algorithm;

/**
 * 岛屿的最大面积
 */
public class MaxAreaOfIsland {

    public static int maxAreaOfIsland(int[][] grid) {
        int result=0;
        for (int row = 0; row < grid.length; row++) {
            for (int col = 0; col < grid[0].length; col++) {
                int dfs = dfs(row, col, grid);
                if (dfs>result){
                    result =dfs;
                }
            }
        }
        return result;
    }

    public static int dfs(int row,int col,int[][]grid){
        if (row<0||row>=grid.length||col<0||col>=grid[0].length||grid[row][col]==0){
            return 0;
        }
        grid[row][col]=0;
        int count=1;
        count+=dfs(row-1,col,grid);
        count+=dfs(row+1,col,grid);
        count+=dfs(row,col-1,grid);
        count+=dfs(row,col+1,grid);
        return count;
    }

    public static void main(String[] args) {
        
    }
}
